using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using DataAccessLayer;

using NUnit.Framework;

namespace Entities
{
    [TestFixture]
    public class ReviewerFixture:ConnectionFixture
    {
        private static readonly string reviewerName = "Test Reviewer";

        private ReviewerGateway gateway;
        private RecordingDataSet recordingDataSet;
        private long insertedId;

        [SetUp]
        public void SetUp() {
            gateway = new ReviewerGateway(Connection);
            recordingDataSet = new RecordingDataSet();
            insertedId = gateway.Insert(reviewerName, recordingDataSet);
        }

        [TearDown]
        public void TearDown()
        {
            gateway.Delete(insertedId, recordingDataSet);
        }

        [Test]
        public void Retrieve()
        {
            RecordingDataSet.ReviewerRow row = gateway.FindById(insertedId, new RecordingDataSet());
            Assert.AreEqual(insertedId, row.id);
            Assert.AreEqual(reviewerName, row.name);
        }

        [Test]
        public void Delete()
        {
            RecordingDataSet emptyDataSet = new RecordingDataSet();
            long deletedId = gateway.Insert("Delete Reviewer", emptyDataSet);

            gateway.Delete(deletedId, recordingDataSet);
            Assert.IsNull(gateway.FindById(deletedId, recordingDataSet));
        }

        [Test]
        public void Update()
        {
            RecordingDataSet.ReviewerRow row = gateway.FindById(insertedId, recordingDataSet);
            row.name = "Modified Name";
            gateway.Update(recordingDataSet);
            Assert.AreEqual("Modified Name", gateway.FindById(insertedId, new RecordingDataSet()).name);
        }

    }
}
